package com.allin.http.request;

import android.text.TextUtils;

import com.allin.http.ParamUtil;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;

import java.util.Map;

/**
 * Created by zhy on 15/11/6.
 */
public class OkHttpGetRequest extends OkHttpRequest
{
    protected OkHttpGetRequest(String url, Object tag, Map<String, Object> params, Map<String, String> headers)
    {
        super(url, tag, params, headers);
    }

    /**
     * 构建GET请求
      * @return
     */
    @Override
    protected Request buildRequest()
    {
        if (TextUtils.isEmpty(url))
        {
            throw new IllegalArgumentException("url can not be empty!");
        }
        //append params , if necessary
        url = ParamUtil.appendParams(url, params);  //转换成带参数的url  url?key=value&key2=value2
        Request.Builder builder = new Request.Builder();
        //add headers , if necessary
        appendHeaders(builder,headers);
        builder.url(url).tag(tag);
        return builder.build();
    }

    @Override
    protected RequestBody buildRequestBody()
    {
        return null;
    }

}

